%{
#include <stdlib.h>
#include <stdio.h>
#include "monflag.tab.h"
%}

%option yylineno
%option stack
%option nodefault
%x comment string defzero pp_else
%s ifdef
%%

   /* Handle comments */
"/*"         yy_push_state(comment);
<comment>[^*\n]*        /* eat anything that's not a '*' */
<comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
<comment>\n             /*++yylineno;*/
<comment>"*"+"/"        yy_pop_state();

#if[ ]*0  			yy_push_state(defzero);
<defzero>#endif 	yy_pop_state();
<defzero>[^#] 		/* */

#define { return DEFINE; }

MS_[A-Z_0-9]+     {yylval.s = strdup(yytext+3); return SOUND;}
MR_[A-Z_0-9]+     {yylval.s = strdup(yytext+3); return RESIST;}
MR2_[A-Z_0-9]+     {yylval.s = strdup(yytext+4); return RESIST;}
M[123V]_[A-Z_0-9]+     {yylval.s = strdup(yytext+3); return FLAG;}
MZ_[A-Z_0-9]+     {yylval.s = strdup(yytext+3); return SIZE;}
MH_[A-Z_0-9]+     {yylval.s = strdup(yytext+3); return RACE;}
G_[A-Z_0-9]+     {yylval.s = strdup(yytext+2); return GENO;}
-?[0-9]+       {yylval.i = atoi(yytext); return INT;}
\(-?[0-9]+\)   {yylval.i = atoi(yytext+1); return INT;}
0x[0-9a-fA-F]+	   {yylval.i = (int)strtol(yytext+2, NULL, 16); return INT;}
0x[0-9a-fA-F]+U?L	   {yylval.l = strtol(yytext+2, NULL, 16); return INT;}
[A-Z_]+
[ \t]+  /* eat */
\n      /* eat */
^[^#]       /* eat */

[()|]			{ return yytext[0]; }

#ifdef				{ yy_push_state(ifdef); }
#else    			{ yy_push_state(pp_else); }
<pp_else>.
<pp_else>\n
<pp_else>#endif[^\n]*  { yy_pop_state(); yyless(0); }
<ifdef>#endif[^\n]*    { yy_pop_state(); }

#ifndef[^\n]+  { return IFNDEF; }
<INITIAL>#endif[^\n]*   { return ENDIF; }
<<EOF>> {return THE_END;}
%%

int yywrap() {
 return 1;
}
